/*
Written by Emily Smith-Greenaway (emilysmithgreenaway.org; smithgre@usc.edu) 
This do-file generates maternal infant mortality estimates 
reported in S5 of:
Smith-Greenaway, E. and J. Trinitapoli. 2020. Maternal Cumulative Prevalence Measures 
of Child Mortality Show Heavy Burden in Sub-Saharan Africa. Proceedings of the National Academy of Sciences
*/
********************************
********************************
********************************
********************************weighted MOM region-level estimates 
********************************
********************************
********************************
clear 
cd ""
use "Smith-GreenawayTrinitapoliPNAS2020data.dta"

drop if country>=21 & country<=36
drop if momcurrentage<=44

gen svyweight = v005/1000000
gen strata = v022
replace strata=v021    if v000=="BF4" & strata==.
replace strata=v021    if v000=="UG6"
replace strata=sstrata if v000=="ZW" & v007==1988

svyset [pweight=svyweight], psu(v001) strata(strata) 

sort countryname v007
egen regionyear=concat(region v007)
destring regionyear, replace
egen nvals=group(regionyear)

keep countryname regionyear momcurrentage nvals everdie v007 v005

forv i=1/577 {
gen anydeath4549_`i'=. 
replace anydeath4549_`i'=0 if momcurrentage>=45 &  nvals==`i'
replace anydeath4549_`i'=1 if everdie==1 & momcurrentage>=45 & nvals==`i'
egen anysummary4549_`i'=wtmean(anydeath4549_`i') if nvals==`i', weight(v005) 
replace anysummary4549_`i'=anysummary4549_`i'*1000
}

gen offspring4549=. 
forv i=1/577 {
replace offspring4549=anysummary4549_`i' if nvals==`i'
}

duplicates drop regionyear, force 
sort countryname v007
browse countryname v007 regionyear offspring4549 
